package com.jltx.xq.appexitpro;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

/**
 * @author jltxseo
 * @date 2017/03/24.
 * @description:
 */

public class BaseAppCompatActivity extends AppCompatActivity implements BaseAppCompatApp{
    private static String TAG = "BaseAppCompatActivity";
    private int countOne = 0;
    private int countTwo = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG,getLogMsg("onCreate"));
        Intent intent = getIntent();
        String oneValue = intent.getStringExtra(Constance.FIRST_DATA_KEY);
        String twoValue = intent.getStringExtra(Constance.SECONDE_DATA_KEY);
        Log.d(TAG,getLogMsg("onCreate.oneValue=>"+oneValue+".twoValue=>"+twoValue));
        if(savedInstanceState != null){
            Log.d(TAG,getLogMsg("onCreate.savedInstanceState != null"));
        }else {
            Log.d(TAG,getLogMsg("onCreate.savedInstanceState == null"));
        }
        if(savedInstanceState != null){
            countOne = savedInstanceState.getInt(Constance.ONE_BUNDLE_DATA_KEY);
            countTwo = savedInstanceState.getInt(Constance.TWO_BUNDLE_DATA_KEY);
        }
    }


    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG,getLogMsg("onStart"));
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG,getLogMsg("onResume"));
        Log.d(TAG,getLogMsg("onResume.countOne=>"+countOne));
        Log.d(TAG,getLogMsg("onResume.countTwo=>"+countTwo));
    }


    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG,getLogMsg("onPause"));
    }


    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG,getLogMsg("onStop"));
    }


    @Override
    public void finish() {
        super.finish();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Log.d(TAG,getLogMsg("finish"));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Log.d(TAG,getLogMsg("onDestroy"));
    }

    @Override
    public void onExitFinish() {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Log.d(TAG,getLogMsg("onExitFinish"));
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        Log.d(TAG,getLogMsg("onSaveInstanceState"));
        countOne = countOne + 1;
        countTwo = countTwo + 2;
        outState.putInt(Constance.ONE_BUNDLE_DATA_KEY,countOne);
        outState.putInt(Constance.TWO_BUNDLE_DATA_KEY,countTwo);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        Log.d(TAG,getLogMsg("onRestoreInstanceState"));

        super.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG,getLogMsg("onActivityResult")+".requestCode=>"+requestCode+".resultCode=>"+resultCode+".data=>"+(data != null ? "data != null" : "data == null"));
        super.onActivityResult(requestCode, resultCode, data);
    }

    private String getLogMsg(String apiStr){
        return getClass().getSimpleName() + "."+apiStr;
    }
}
